import 'package:gold/generated/json/base/json_convert_content.dart';
import 'package:gold/model/pool_list_model.dart';

PoolListModel $PoolListModelFromJson(Map<String, dynamic> json) {
  final PoolListModel poolListModel = PoolListModel();
  final List<PoolRankModel>? data = (json['data'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<PoolRankModel>(e) as PoolRankModel).toList();
  if (data != null) {
    poolListModel.data = data;
  }
  final int? total = jsonConvert.convert<int>(json['total']);
  if (total != null) {
    poolListModel.total = total;
  }
  final int? count = jsonConvert.convert<int>(json['count']);
  if (count != null) {
    poolListModel.count = count;
  }
  final int? perPage = jsonConvert.convert<int>(json['per_page']);
  if (perPage != null) {
    poolListModel.perPage = perPage;
  }
  final int? currentPage = jsonConvert.convert<int>(json['current_page']);
  if (currentPage != null) {
    poolListModel.currentPage = currentPage;
  }
  final int? totalPages = jsonConvert.convert<int>(json['total_pages']);
  if (totalPages != null) {
    poolListModel.totalPages = totalPages;
  }
  return poolListModel;
}

Map<String, dynamic> $PoolListModelToJson(PoolListModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['data'] = entity.data?.map((v) => v.toJson()).toList();
  data['total'] = entity.total;
  data['count'] = entity.count;
  data['per_page'] = entity.perPage;
  data['current_page'] = entity.currentPage;
  data['total_pages'] = entity.totalPages;
  return data;
}

extension PoolListModelExtension on PoolListModel {
  PoolListModel copyWith({
    List<PoolRankModel>? data,
    int? total,
    int? count,
    int? perPage,
    int? currentPage,
    int? totalPages,
  }) {
    return PoolListModel()
      ..data = data ?? this.data
      ..total = total ?? this.total
      ..count = count ?? this.count
      ..perPage = perPage ?? this.perPage
      ..currentPage = currentPage ?? this.currentPage
      ..totalPages = totalPages ?? this.totalPages;
  }
}

PoolRankModel $PoolRankModelFromJson(Map<String, dynamic> json) {
  final PoolRankModel poolRankModel = PoolRankModel();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    poolRankModel.id = id;
  }
  final String? totalAmount = jsonConvert.convert<String>(json['total_amount']);
  if (totalAmount != null) {
    poolRankModel.totalAmount = totalAmount;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    poolRankModel.createdAt = createdAt;
  }
  final String? updatedAt = jsonConvert.convert<String>(json['updated_at']);
  if (updatedAt != null) {
    poolRankModel.updatedAt = updatedAt;
  }
  final int? userId = jsonConvert.convert<int>(json['user_id']);
  if (userId != null) {
    poolRankModel.userId = userId;
  }
  final int? poolId = jsonConvert.convert<int>(json['pool_id']);
  if (poolId != null) {
    poolRankModel.poolId = poolId;
  }
  final int? planId = jsonConvert.convert<int>(json['plan_id']);
  if (planId != null) {
    poolRankModel.planId = planId;
  }
  final int? ranks = jsonConvert.convert<int>(json['ranks']);
  if (ranks != null) {
    poolRankModel.ranks = ranks;
  }
  final int? diffAmount = jsonConvert.convert<int>(json['diff_amount']);
  if (diffAmount != null) {
    poolRankModel.diffAmount = diffAmount;
  }
  final PoolRankMemberModel? member = jsonConvert.convert<PoolRankMemberModel>(json['member']);
  if (member != null) {
    poolRankModel.member = member;
  }
  final String? rate = jsonConvert.convert<String>(json['rate']);
  if (rate != null) {
    poolRankModel.rate = rate;
  }
  final String? lastAverage = jsonConvert.convert<String>(json['last_average']);
  if (lastAverage != null) {
    poolRankModel.lastAverage = lastAverage;
  }
  final int? lastCount = jsonConvert.convert<int>(json['last_count']);
  if (lastCount != null) {
    poolRankModel.lastCount = lastCount;
  }
  return poolRankModel;
}

Map<String, dynamic> $PoolRankModelToJson(PoolRankModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['total_amount'] = entity.totalAmount;
  data['created_at'] = entity.createdAt;
  data['updated_at'] = entity.updatedAt;
  data['user_id'] = entity.userId;
  data['pool_id'] = entity.poolId;
  data['plan_id'] = entity.planId;
  data['ranks'] = entity.ranks;
  data['diff_amount'] = entity.diffAmount;
  data['member'] = entity.member?.toJson();
  data['rate'] = entity.rate;
  data['last_average'] = entity.lastAverage;
  data['last_count'] = entity.lastCount;
  return data;
}

extension PoolRankModelExtension on PoolRankModel {
  PoolRankModel copyWith({
    int? id,
    String? totalAmount,
    String? createdAt,
    String? updatedAt,
    int? userId,
    int? poolId,
    int? planId,
    int? ranks,
    int? diffAmount,
    PoolRankMemberModel? member,
    String? rate,
    String? lastAverage,
    int? lastCount,
  }) {
    return PoolRankModel()
      ..id = id ?? this.id
      ..totalAmount = totalAmount ?? this.totalAmount
      ..createdAt = createdAt ?? this.createdAt
      ..updatedAt = updatedAt ?? this.updatedAt
      ..userId = userId ?? this.userId
      ..poolId = poolId ?? this.poolId
      ..planId = planId ?? this.planId
      ..ranks = ranks ?? this.ranks
      ..diffAmount = diffAmount ?? this.diffAmount
      ..member = member ?? this.member
      ..rate = rate ?? this.rate
      ..lastAverage = lastAverage ?? this.lastAverage
      ..lastCount = lastCount ?? this.lastCount;
  }
}

PoolRankMemberModel $PoolRankMemberModelFromJson(Map<String, dynamic> json) {
  final PoolRankMemberModel poolRankMemberModel = PoolRankMemberModel();
  final int? uid = jsonConvert.convert<int>(json['uid']);
  if (uid != null) {
    poolRankMemberModel.uid = uid;
  }
  final String? nickname = jsonConvert.convert<String>(json['nickname']);
  if (nickname != null) {
    poolRankMemberModel.nickname = nickname;
  }
  final String? avatar = jsonConvert.convert<String>(json['avatar']);
  if (avatar != null) {
    poolRankMemberModel.avatar = avatar;
  }
  return poolRankMemberModel;
}

Map<String, dynamic> $PoolRankMemberModelToJson(PoolRankMemberModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['uid'] = entity.uid;
  data['nickname'] = entity.nickname;
  data['avatar'] = entity.avatar;
  return data;
}

extension PoolRankMemberModelExtension on PoolRankMemberModel {
  PoolRankMemberModel copyWith({
    int? uid,
    String? nickname,
    String? avatar,
  }) {
    return PoolRankMemberModel()
      ..uid = uid ?? this.uid
      ..nickname = nickname ?? this.nickname
      ..avatar = avatar ?? this.avatar;
  }
}